<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
 
<div id="box">
    <p>页面在
    <span id="Os">5</span>
     s后跳转
    </p>
    <button id="btn" onclick="stop()">停止</button>
</div>
  
<script> 
       var Os=document.getElementById("Os");
    var num=5;
    var timer=setInterval(function () {
        num--;
        Os.innerText=num;
        if(num==0){
            window.location.href="./index.html";
        }
    },1000)
    function stop() {
        clearInterval(timer);
    }
</script>

</body>
</html>